# -*- coding: utf-8 -*-
#
# Author:: hanjunfeng
# Date:: 2021/3/22
import pymysql




class _Connection():
    def __init__(self, **kwargs):
        self.conn = pymysql.connect(**kwargs)

    def exec_sql(self, sql):
        self.cursor = self.conn.cursor()
        self.cursor.execute(sql)
        res = self.cursor.fetchall()
        return res

    def close(self):
        self.cursor.close()
        self.close()


if __name__ == "__main__":
    f_b_w_offline = {
        "host": "10.225.114.49",
        "port": 3306,
        "user": "f_b_w",
        "password": "FohgX0hRdtoaL4g_QgGMAyZtQNSHTAKE"
    }

    # db = pymysql.connect(host="10.225.114.49", port=3306, user="f_b_w",
    #                      password="FohgX0hRdtoaL4g_QgGMAyZtQNSHTAKE")

    # db = pymysql.Connect(**f_b_w_offline)

    # db = get_mysql_conn(**f_b_w_offline)

    # db.f_b_w_offline
    # 使用 cursor() 方法创建一个游标对象 cursor
    # cursor = db.cursor()

    # 使用 execute()  方法执行 SQL 查询
    # cursor.execute("SELECT VERSION()")
    #
    # # 使用 fetchone() 方法获取单条数据.
    # data = cursor.fetchone()
    #
    # print("Database version : %s " % data)
    #
    # # 关闭数据库连接
    # db.close()

    conn = _Mysql(**f_b_w_offline)
    res = conn.exec_sql("SELECT VERSION()")
    print(res)
